<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" title="校园资讯" back-icon-color='#333333' height="50" :border-bottom="false">
			<view class="" style="margin-left: 600rpx; display: flex;align-content: center;"
				@click="$toLink('../add_vacate/add_vacate',{})">
				<image src="../../static/tupian95.png" mode="widthFix" style="width: 30rpx;"></image>
			</view>
		</u-navbar>
		<view class="top">
			<view class="topBox">
				<view v-for="(topItem,topIndex) of message" :key="topIndex" :data-name="topIndex" @click="changeIndex"
					:class="[activeIndex==topIndex?'con':'']">
					<text></text>
					{{topItem}}
				</view>
			</view>
		</view>
		<view id="campus_list">
			<view class="per_campus"
				@click="$toLink('../information_details/information_details',{id:item.school_news_id})"
				v-for="(item,index) in schoolNews" :key="index">
				<view class="left_pic">
					<image :src="item.picsUrl" mode="widthFix"></image>
				</view>
				<view class="right_campus">
					<view class="caption">
						<text>{{item.title}}</text>
					</view>
					<view class="matter">
						{{item.text}}
					</view>
					<view class="ms">
						<text>{{item.create_time}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../request.js'
	export default {
		data() {
			return {
				activeIndex: 0,
				message: ['全部', '活动', '学习', '教育'],
				school_news: [],
			}
		},
		methods: {
			changeIndex(e) {
				console.log(e.currentTarget.dataset.name);
				let index = e.currentTarget.dataset.name;
				this.activeIndex = index;
				switch(this.activeIndex){
					case 0:
					this.getSchoolNews()
					break;
					case 1:
					this.getSchoolNews('活动')
					break;
					case 2:
					this.getSchoolNews('学习')
					break;
					case 3:
					this.getSchoolNews('教育')
					break;
				}
			},
			getSchoolNews(param) {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				this.school_news=[];
				let _this = this;
				request({
					url: base_url + 'teacher/schoolNews/lists',
					method: 'post',
					data: {
						type:param?param:'',
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data.data);
							_this.school_news = res.data.data.data;
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}
			
					}
				})
			},
		},
		onLoad() {
			this.getSchoolNews();
		},
		computed:{
			schoolNews() {
				if (this.school_news) {
					this.school_news.forEach(item => {
						this.$set(item, 'picsUrl', `${uni.getStorageSync('host')}${item.pics}`);
					})
					return this.school_news;
				} else {
					return [];
				}
			},
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		// background: #F2F2F2;

		.top {
			width: 100%;
			height: 95rpx;
			background: #fff;
			overflow: hidden;

			.topBox {
				width: 100%;
				margin-top: 30rpx;
				height: 65rpx;
				background: #fff;
				position: relative;
				display: flex;
				justify-content: space-evenly;

				view {
					height: 65rpx;
					line-height: 65rpx;
					width: 120rpx;
					text-align: center;
					font-size: 30rpx;
					color: #fff;
					color: #333333;

					text {
						display: none;
					}


				}

				.con {
					position: relative;
					height: 65rpx;
					line-height: 65rpx;
					color: #2f96fe;
					width: 120rpx;

					text {
						display: block !important;
						position: absolute;
						width: 120rpx;
						height: 4rpx;
						background: #2f96fe;
						bottom: 0rpx;
						left: 0rpx;
					}
				}

			}
		}

		#campus_list {
			width: 100%;

			.per_campus {
				width: 710rpx;
				margin-left: 20rpx;
				height: 190rpx;
				border-bottom: 1rpx solid #e5e5e5;
				background-color: #fff;
				display: flex;
				justify-content: flex-start;

				.left_pic {
					width: 203rpx;
					height: 147rpx;
					margin-top: 22rpx;
					overflow: hidden;

					image {
						&:nth-child(1) {
							width: 203rpx;
						}
					}
				}

				.right_campus {
					width: 485rpx;
					margin-top: 25rpx;
					height: 165rpx;
					overflow: hidden;
					margin-left: 22rpx;

					.caption {
						margin-top: 3rpx;
						width: 100%;

						text {
							&:nth-child(1) {
								color: #333333;
								font-size: 26rpx;
							}
						}
					}

					.matter {
						width: 100%;
						margin-top: 10rpx;
						color: #666666;
						font-size: 24rpx;
					}

					.ms {
						width: 100%;
						height: 21rpx;
						margin-top: 0rpx;

						text {
							color: #999999;
							font-size: 21rpx;

							&:nth-child(1) {
								width: 120rpx;
							}

							&:nth-child(2) {}
						}
					}
				}
			}

		}
	}
</style>
